package com.example.demo.service;

import com.example.demo.entity.SaleOrder;
import com.example.demo.mapper.SaleOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 销售订单MyBatis服务层
 */
@Service
public class SaleOrderMyBatisService {
    
    @Autowired
    private SaleOrderMapper saleOrderMapper;
    
    /**
     * 查询指定时间范围的销售订单
     */
    public List<SaleOrder> findByDateRange(LocalDateTime startDate, LocalDateTime endDate) {
        return saleOrderMapper.findByDateRange(startDate, endDate);
    }
    
    /**
     * 根据收银员ID查询订单
     */
    public List<SaleOrder> findByCashierId(Long cashierId) {
        return saleOrderMapper.findByCashierId(cashierId);
    }
    
    /**
     * 查询今日销售统计
     */
    public Map<String, Object> getTodaySalesStats() {
        return saleOrderMapper.getTodaySalesStats();
    }
    
    /**
     * 查询月度销售统计
     */
    public Map<String, Object> getMonthlySalesStats(Integer year, Integer month) {
        return saleOrderMapper.getMonthlySalesStats(year, month);
    }
    
    /**
     * 查询热销商品排行
     */
    public List<Map<String, Object>> getTopSellingProducts(Integer limit) {
        return saleOrderMapper.getTopSellingProducts(limit);
    }
    
    /**
     * 根据支付方式统计销售
     */
    public List<Map<String, Object>> getSalesByPaymentMethod() {
        return saleOrderMapper.getSalesByPaymentMethod();
    }
    
    /**
     * 查询会员消费统计
     */
    public List<Map<String, Object>> getMemberConsumptionStats() {
        return saleOrderMapper.getMemberConsumptionStats();
    }
    
    /**
     * 查询销售趋势（按天）
     */
    public List<Map<String, Object>> getSalesTrendByDay(Integer days) {
        return saleOrderMapper.getSalesTrendByDay(days);
    }
    
    /**
     * 查询销售趋势（按小时）
     */
    public List<Map<String, Object>> getSalesTrendByHour(String date) {
        return saleOrderMapper.getSalesTrendByHour(date);
    }
    
    /**
     * 查询退货订单
     */
    public List<SaleOrder> findReturnOrders() {
        return saleOrderMapper.findReturnOrders();
    }
    
    /**
     * 统计指定时间段的销售金额
     */
    public Double getTotalSalesAmount(LocalDateTime startDate, LocalDateTime endDate) {
        return saleOrderMapper.getTotalSalesAmount(startDate, endDate);
    }
}
